package com.yb.basic;

import java.util.*;

public class WrongExamples {
    /**
     * String的split方法空字符串问题
     */
    static void example1() {
        String a = "a,b,c,,";
        String[] arr = a.split(",");
        System.out.print(arr.length);//3
    }

    /**
     *  Arrays.asList问题
     *      对基本类型的数组支持不友好
     *      转换后不能调用add/remove方法
     */
    static void example2(){
//        int[] arr = {1, 2};
//        List list = Arrays.asList(arr);
//        list.forEach(i->System.out.println(i));//[I@2d98a335
//        System.out.println(list.size());//1

//        String[] arr1 = {"a","b","c"};
//        List list1 = Arrays.asList(arr1);
        //list1.add("d");//java.lang.UnsupportedOperationException
        //list1.remove("a");//java.lang.UnsupportedOperationException

//        list1.forEach(s->System.out.println(s));
//        arr1[0] = "d";
//        System.out.println(list1.get(0));
//        list1.set(0,"e");
//        System.out.println(arr1[0]);


//        List<String> list2 = Arrays.asList("aa","bb","cc");
//        for (String s:list2) {
//            System.out.println(s);
//        }
//        list2.forEach(s->System.out.println(s));


        List<String> list3 = new ArrayList<>();
        list3.add("aa");
        list3.add("bb");
        list3.add("cc");
        list3.add("aa");
        list3.add("dd");
        list3.add("aa");
        list3.add("ee");
        Iterator<String> it = list3.iterator();
        while(it.hasNext()){
            if("aa".equals(it.next())){
                it.remove();
            }
        }
        list3.forEach(s->System.out.println(s));
    }

    public static void main(String[] args) {
        //example1();
        example2();
    }
}
